

import 'package:erp/UI/CodeResources/Localization.dart';
import 'package:erp/UI/Components/HeroLogo.dart';
import 'package:erp/UI/Components/HeroLogoSliverAppbar.dart';
import 'package:erp/UI/Components/LogoScaffold.dart';
import 'package:erp/UI/Pages/ActionItemMetaData.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/CustomerPages/CustomerPage.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/CustomerTypePage/CustomerTypePage.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/ProductManagementPages/ProductInfoManagement.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/ProductTypePages/ProductTypePage.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/SupplierPages/SupplierInformationPage.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/SupplierTypePages/SupplierTypePage.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/WareHousePages/WareHousePage.dart';
import 'package:flutter/material.dart';

class BasicInformationManagementPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var currentLocale = AppLocalizations.of(context);
    var items = [
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => WareHousePageStateless(),),);
      }, label: "ئامبارلار", assetsImageName: "assets/pictures/warehause.png", heroName: "wareHouseImage"),
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => SupplierTypePage()));
      }, label: "مال تەمىنلىگۈچىلەر تۈرلىرى", assetsImageName: "assets/pictures/purchases.png", heroName: "SupplierTypeHero"),
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => SupplierInformationPage()));
      }, label: "مال تەمىنلىگۈچىلەر", assetsImageName: "assets/pictures/purchases.png", heroName: "SupplierInformationPageImage"),
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => ProductInfoManagement()));
      }, label: "تاۋارلار", assetsImageName: "assets/pictures/boxes.png", heroName: "ProductInfoManagementPageLogo"),
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => ProductTypePage()));
      }, label: "تاۋار تۈرلىرى", assetsImageName: "assets/pictures/abc.png", heroName: "PeoductTypePageLogoHero"),
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => CustomerTypePage()));
      }, label: "خىرىدارلار تۈرلىرى", assetsImageName: "assets/pictures/salesman.png", heroName: "CustomerTypeHero"),
      ActionItemMeta(action: (){
        Navigator.of(context).push(MaterialPageRoute(builder: (context) => CustomerPage()));
      }, label: "خىرىدارلار", assetsImageName: "assets/pictures/salesman.png", heroName: "CustomerHero"),
    ].map((item) => buildItem(context, item)).toList();

    return Directionality(
        textDirection: currentLocale.textDirection,
        child: Scaffold(
          body: CustomScrollView(
            slivers: <Widget>[
              SliverAppBar(
                expandedHeight: 250.0,
                pinned: true,
                flexibleSpace: FlexibleSpaceBar(
                  title: Text("ئاساسى ئۇچۇرلار"),
                  centerTitle: true,
                  background: Center(
                    child: CircleAvatar(
                      radius: 64.0,
                      backgroundColor: Colors.white,
                      child: Hero(
                        tag: "BasicInformationManagement",
                        child: Image.asset("assets/pictures/team.png", width: 90.0, height: 90.0,),
                      ),
                    ),
                  ),
                ),
              ),
              SliverToBoxAdapter(
                child: SizedBox(
                  height: 20.0,
                ),
              ),
              SliverGrid(
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3,
                ),
                delegate: SliverChildListDelegate(items),
              )
            ],
          ),
        )
    );
  }

   Widget buildItem(BuildContext context, ActionItemMeta meta){
    return GestureDetector(
      child: Column(
        children: <Widget>[
          Hero(tag: meta.heroName, child: Image.asset(meta.assetsImageName, width: 50.0, height: 50.0,),),
          Text(meta.label, textAlign: TextAlign.center,)
        ],
      ),
      onTap: meta.action,
    );
   }
}


